import unittest

import jsonschema

from api.ihrm_login_api import IhrmLoginApi


class TestIhrmLogin(unittest.TestCase):
    def test01_login_success(self):
        # 组织请求数据
        json_data = {"mobile": "13800000002", "password": "123456"}
        # 调用封装接口
        resp = IhrmLoginApi.login(json_data)
        print("登陆成功", resp.json())
        # 断言
        # assert_util(self, resp, 200, True, 10000, "操作成功")
        # 断言校验响应状态码
        self.assertEqual(200,resp.status_code)
        # 校验规则
        schema = {
            "type": "object",
            "properties": {
                "success": {"const": True},
                "code": {"const": 10000},
                "message": {"const": "操作成功"},
                "data": {"type": "string"}
            },
            "required": {"success", "code", "message", "data"}
        }

        # 调用jsonschema校验函数
        jsonschema.validate(instance=resp.json(), schema=schema)
